<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html ng-app="app" id="ng-app">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<%@include file="/include/style.jsp"%>
<%@include file="/include/script.jsp"%>
<script type="text/javascript">
function RoleCtrl($scope,$http) {
	$scope.formCondition = {};
	
	Pagination.initialize("/role/findPage", $scope, $http);
	
	$scope.init = function() {
		$scope.search();
	};
	
	$scope.createRole = function() {
		window.location.href = "/role/add";
	};
	
	$scope.editRole = function(role) {
		window.location.href = "/role/edit/" + role.id;
	};
	
	$scope.deleteRole = function(role) {
		Message.confirm("确认", "确定要删除角色“" + role.name + "”吗？", function() {
			$http.post("/role/delete/" + role.id).success(function(response) {
				if(response.success) {
					$scope.search();
				} else {
					Message.error("错误", response.message || '操作失败！');
				}
			});
		});
	};
	
	$scope.init();
}

app.controller('RoleCtrl', RoleCtrl);
</script>
</head>
<body ng-controller="RoleCtrl">
	<div class="toolbar">
		<div class="left-area">
			<form ng-submit="search()">
				<input type="text" id="name" ng-model="formCondition.name" placeholder="角色名模糊匹配" class="form-control search-box">
			</form>
		</div>
  		<div class="right-area">
  			<permission:valid permission="<%=Constants.ROLE_CUD%>">
				<button class="btn btn-success" ng-click="createRole()"><i class="fa fa-plus"></i> 新增 </button>
			</permission:valid>
  		</div>
	</div>
	
	<div ng-show="page.rows.length>0">
		<table class="data-table">
			<thead>
				<tr>
					<th width="5%">序号</th>
					<th width="20%">角色名称</th>
					<th width="40%">描述</th>
					<th width="15%">操作</th>
				</tr> 
			</thead>
			<tbody class="ng-scope">
				<tr ng-repeat="role in page.rows">
					<td align="center">{{$index + 1}}</td>
					<td>{{role.name}}</td>
					<td>{{role.description}}</td>
					<td align="center">
						<permission:valid permission="<%=Constants.ROLE_CUD%>">
							<span class="btn btn-link" ng-click="editRole(role)" ng-show="role.reserved!=1"><i class="fa fa-pencil"></i> 修改</span>
							<span class="btn btn-link" ng-click="deleteRole(role)" ng-show="role.reserved!=1"><i class="fa fa-trash"></i> 删除</span>
						</permission:valid>
					</td>
				</tr>
			</tbody>
		</table>
		
		<%@include file="/include/pageBar.jsp"%>
	</div>
	
	<div class="alert alert-success" style="clear: both;" ng-show='page.rows.length==0'>
		暂无数据！
	</div>
</body>
</html>